<%@ page language="java" contentType="text/html; charset=UTF-8" %>

<script src="<c:url value='/resources/js/manage.js'/>"></script>
<c:import url="../../../template/layout.jsp" charEncoding="UTF-8">
  <c:param name="title" value="角色列表"/>
  <c:param name="body">
    <script>
      $(document).ready(
              function () {
                var id = $(".id").val();
                if (id) {

                }

              });
    </script>


    <div class="content-title">角色列表
      <p>${message.msg}</p>
    </div>
    <div class="container"
         style="background-color:#DCEAF4; width:1300px; height:500px;border-radius: 0px 0px 0px 0px;">
        <c:if test="${message!=null}">
            <div class="alert alert-danger" role="alert">${message.msg}</div>
        </c:if>
      <div class="btn-group pull-right" style="margin-bottom:8px;">
        <a class="btn btn-lg btn-primary" href="${pageContext.request.contextPath}/system/role/edit">
          <span class="glyphicon"></span> 添加角色
        </a>
      </div>
      <p></p>
        <div class="col-sm-5 col-sm-offset-1">
            <form id="searchForm" method="get" action="/system/role/list"
                  name="user">
                <div class="input-group">
                    <input id="pageNo" name="pageNo" type="hidden" value="${pager.pageNo}"/>
                    <input id="pageSize" name="pageSize" type="hidden" value="${pager.pageSize}"/>


                </div>
            </form>
        </div>
      <div class="main-content">

        <table class="table">
          <thead>
          <tr>
            <th>角色名</th>
            <th>角色描述</th>
            <th>权限</th>
            <th>操作</th>
          </tr>
          </thead>
          <tbody>
          <c:forEach items="${pager.list}" var="role">
            <%--<s:iterator value="#request.roleList" var="role">--%>
            <tr class="success">
              <td>${role.rolename}</td>
              <td>${role.role_description}</td>
              <td>${role.viewPermissions}</td>
              <td>
                <button onclick="editRole('<c:url value="/system/role/getRole?id=${role.id}"/>')"
                        class="btn btn-primary btn-xs"
                        data-toggle="modal" data-target="#editRole">编辑
                </button>
                &nbsp;&nbsp;
                <button class="btn btn-primary btn-xs"
                        href="javascript:void(0)" data-toggle="tooltip" title="删除"
                        onclick="if (confirm('确认要删除本记录吗？此操作将不可恢复！'))
                                location = '<c:url
                                value="/system/role/delete?id=${role.id}"/>';
                                return false;">删除
                </button>


              </td>
            </tr>
            <%--</s:iterator>--%>
          </c:forEach>

          </tbody>
        </table>
      </div>
        <div class="row">
            <div class="col-sm-12">
                    ${pager}
            </div>
        </div>
    </div>
    <script type="text/javascript">

      function editRole(path) {
        $.ajax({
          url: path,
          type: 'get',
          async: true,
          dataType: 'json',
          success: function (role) {
              $('#edit_id').val(role.id);
            $('#edit_rolename').val(role.rolename);
            $('#edit_role_description').val(role.role_description);
alert(role.allPermissions);
                $("#edit_permissions").empty();
            $.each(role.allPermissions, function (idx, obj) {
              var inp = '<input class="edit_check" type="checkbox" name="permission" value="' + obj.id + '"/>' + '&nbsp;&nbsp;' + obj.per_description;
              $("#edit_permissions").append(inp);
              /*if (role.rolename == obj.rolename) {
              }*/
            });
          }
        });
      }


    </script>
    <%--编辑模态框--%>
    <div class="modal fade" id="editRole" tabindex="-1" role="dialog">
      <div class="modal-dialog modal-lg">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">
              <span aria-hidden="true">&times;</span>
              <span class="sr-only">Close</span>
            </button>
            <h3 class="modal-title">编辑</h3>
          </div>
          <div class="modal-body">
              <form action="/system/role/edit" method="POST">

              <div class="form-group">
                <label class="control-label" for="rolename">角色名</label>
                <input type="text" class="form-control" id="edit_rolename" name="rolename" required>
              </div>
              <div class="form-group">
                <label for="edit_realName">角色描述</label>
                <input class="form-control" id="edit_role_description" name="role_description" required/>
              </div>
              <div id="edit_permissions" class="form-group">
                <label>权限</label>
              </div>
                <div class="form-group">
                    <input class="form-control" type="hidden" name="id" id="edit_id"/>
                </div>
              <button class="btn btn-primary btn-lg btn-block" type="submit">
                确定
              </button>
            </form>
          </div>
        </div>
      </div>
    </div>
  </c:param>
</c:import>
